package org.yly.game.rpggame.domain.model.skill;

import java.util.Calendar;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import org.yly.game.rpggame.domain.model.CustomProperty;
import org.yly.game.rpggame.domain.model.TargetType;
/**
 * 玩家添加后的技能
 * @author makefu
 *
 */
public class ActivatedSkill  {
	
	private Skill skill;
	private Date useTime; // 上次使用时间
	
	public ActivatedSkill(Skill skill) {
		this.skill = skill;
	}

	public Skill getSkill() {
		return skill;
	}
	
	/**
	 * 技能是否超过cd时间，超过才可能
	 * 
	 * @return
	 */
	public boolean isUsable() {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(this.useTime);
		calendar.add(Calendar.SECOND, this.skill.getCdTime());
		return calendar.before(new Date());
	}
	
	/**
	 * 使用技能
	 */
	public Set<CustomProperty> use(TargetType targetType) {
		if (this.isUsable()) {
			this.useTime = new Date();
			
			return this.skill.getProperty(targetType);
		}
		return new HashSet<CustomProperty>();
	}
	
	public String getName() {
		return this.skill.getName();
	}
}
